package com.appcenter.application.service;

import com.appcenter.application.config.RemoteProperties;
import com.appcenter.application.dto.externalapi.JobDto;
import com.appcenter.application.dto.externalapi.JobUserDto;
import com.appcenter.application.dto.externalapi.UnitDto;
import com.appcenter.application.dto.externalapi.UserInfoDto;
import com.appcenter.application.expand.ObjectFinal;
import com.appcenter.application.input.externalapi.DataSynchronizeInput;
import com.appcenter.application.mapper.*;
import com.appcenter.application.model.*;
import com.appcenter.application.output.externalapi.DataSynchronizeOutput;
import com.appcenter.jz.Logger.BusinessLogger;
import com.appcenter.jz.Logger.LoggerGenre;
import com.appcenter.jz.app.CurrentUser;
import com.appcenter.jz.config.ErrorJsonResult;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

import static org.apache.http.util.TextUtils.isBlank;

@EnableConfigurationProperties(RemoteProperties.class)
@Service
public class HrToApplicationService {
    @Autowired
    UsersMapper usersMapper;
    @Autowired
    UserService userService;
    @Autowired
    DataMarkService dataMarkService;
    @Autowired
    RolesMapper rolesMapper;
    @Autowired
    PermissionsMapper permissionsMapper;
    @Autowired
    AssortCodeService assortCodeService;
    @Autowired
    ObjectFinal objectFinal;
    @Autowired
    RemoteProperties remoteProperties;
    @Autowired
    private HttpAPIService httpAPIService;
    @Autowired
    AssortCodesMapper assortCodesMapper;
    @Autowired
    ObjectMapper objectMapper;
    @Autowired
    OrgsMapper orgsMapper;
    @Autowired
    OrgUsersMapper orgUsersMapper;
    @Autowired
    OrgService orgService;

    @Autowired
    OrgUserService orgUserService;

    @Autowired
    JobsMapper jobsMapper;

    @Autowired
    OrgJobsMapper orgJobsMapper;
    @Autowired
    JobUsersMapper jobUsersMapper;
    @Autowired
    PermissionService permissionService;

    /**
     * 创建人:Coke
     * 备注: 同步数据
     * 时间: 2019/4/26 13:49
     * 参数:
     */
    public DataSynchronizeOutput DataSynchronize(DataSynchronizeInput input) throws Exception {
        DataSynchronizeOutput output = new DataSynchronizeOutput();
        try {
            BusinessLogger.Info(LoggerGenre.DataSynchronize, "开始同步数据");
            //读取旧版本号
            Long oldVersion = objectFinal.getDataEffectiveVersion();
            //设置新版本号
            Long newVersion = oldVersion + 1;

            Long listOrder = 1L;

            //获取单位信息
            JaxWsDynamicClientFactory dcfUnit = JaxWsDynamicClientFactory.newInstance();
            Client client = dcfUnit.createClient(remoteProperties.getHrUnitService());
            Object[] objectUnits = client.invoke("getAllOrganizations", "UN");
            List<Orgs> completeUnit = new ArrayList<Orgs>();
            List<Jobs> completeJob = new ArrayList<Jobs>();
            List<OrgJobs> completeOrgJob = new ArrayList<OrgJobs>();
            BusinessLogger.Info(LoggerGenre.DataSynchronize, "开始同步单位/部门信息");
            SyncUnitorOrg(objectUnits, newVersion, "单位", completeUnit, listOrder);
            //读取部门信息接口
            Object[] objectOrgs = client.invoke("getAllOrganizations", "UM");
            SyncUnitorOrg(objectOrgs, newVersion, "部门", completeUnit, listOrder);
            //同步岗位信息
            Object[] objectJobs = client.invoke("getAllOrganizations", "@K");
            BusinessLogger.Info(LoggerGenre.DataSynchronize, "开始同步岗位信息信息");
            SyncJob(objectJobs, newVersion, completeUnit, completeJob, completeOrgJob);

            //同步人员信息
            JaxWsDynamicClientFactory dcfUser = JaxWsDynamicClientFactory.newInstance();
            Client clientUser = dcfUser.createClient(remoteProperties.getHrUserService());
            Object[] objectUsers = clientUser.invoke("getHRInfo");
            BusinessLogger.Info(LoggerGenre.DataSynchronize, "开始同步人员信息");
            SyncUserInfo(objectUsers, newVersion, oldVersion, completeUnit, completeJob, completeOrgJob);

            //同步人员兼职信息
            JaxWsDynamicClientFactory dcfJobUser = JaxWsDynamicClientFactory.newInstance();
            Client clientJobUser = dcfJobUser.createClient(remoteProperties.getHrUserService());
            Object[] objectJobUsers = clientJobUser.invoke("getJRuserpost");
            BusinessLogger.Info(LoggerGenre.DataSynchronize, "开始同步人员兼职信息");
            SyncUserpluralism(objectJobUsers, newVersion, completeOrgJob, completeJob, completeUnit);

            objectFinal.editDataEffectiveVersion(newVersion);
            output.setResultCode("10000000");
            output.setResultMsg("导入成功");
        } catch (Exception e) {
            throw new ErrorJsonResult("10000031", e.toString());
        }
        return output;
    }

    /**
     * 创建人:Coke
     * 备注: 同步组织和单位
     * 时间: 2019/4/26 13:49
     * 参数:
     */
    public Boolean SyncUnitorOrg(Object[] objects, Long newVersion, String Genre, List<Orgs> completeUnit, Long listOrder) throws Exception {
        if (objects.length > 0) {
            List<UnitDto> listUnit = objectMapper.readValue(objects[0].toString()
                    .replace('\n', '|')
                    .replace('\t', '|')
                    .replace('\r', '|'), new TypeReference<List<UnitDto>>() {
            });
            BusinessLogger.Info(LoggerGenre.DataSynchronize, "获取到了单位/部门信息", listUnit);
            if (listUnit != null && listUnit.size() > 0) {
                for (int i = 0; i < listUnit.size(); i++) {

                    listOrder += 1;
                    Orgs org = new Orgs();
                    UnitDto unit = listUnit.get(i);
                    try {
                        //主键
                        org.setId(unit.getGuidkey());
                        //部门编码
                        org.setOrgCode(unit.getCodeitemid());
                        //部门名称
                        org.setOrgName(unit.getCodeitemdesc());
                        //补充字段
                        org.setOrgFullName(unit.getB0105());
                        org.setRegisterCode(unit.getB01ag());
                        org.setLegalRepresentative(unit.getB0173());
                        org.setEstablishmentDate(unit.getB01ah());
                        org.setEnterprisesNature(unit.getB01ak());
                        org.setAddress(unit.getB0120());
                        org.setRegisteredCapital(unit.getB01al());
                        org.setCurrency(unit.getB01am());
                        org.setOperationAge(unit.getB01ai());
                        org.setApprovedBusinessScope(unit.getB01aj());
                        org.setRegistrationAuthority(unit.getB01ao());
                        org.setRegistrationDate(unit.getB01au());
                        org.setRegistrationStatus(unit.getB01as());
                        org.setCountry(unit.getB0178());
                        org.setRegistrationPlace(unit.getB0140());
                        org.setAdministrativeDivision(unit.getB01ab());
                        org.setCompanyType(unit.getB01ac());
                        org.setJointVenture(unit.getB01af());
                        org.setIsHaveManagement(unit.getB01aa());
                        org.setCompanyShortName(unit.getB01ad());
                        org.setOfficeAddress(unit.getB01ap());
                        org.setUnitHead(unit.getB0180());
                        org.setCompanyCode(unit.getB01ae());
                        org.setCompanyNumber(unit.getB01an());
                        org.setStartDate(unit.getStart_date());
                        org.setEndDate(unit.getEnd_date());

                        List<Orgs> parents = completeUnit.stream().filter(item -> item.getOrgCode().equals(unit.getParentid())).collect(Collectors.toList());
                        if (parents == null || parents.size() == 0) {
                            //父ID
                            org.setParentId(null);
                            //ID全路径
                            org.setOrgIdPath(unit.getGuidkey());
                            //code全路径
                            org.setOrgCodePath(unit.getCodeitemid());
                            //名称全路径
                            org.setOrgNamePath(unit.getCodeitemdesc());
                            //排序
                            org.setLevel(1L);

                            org.setListOrder(listOrder);
                        } else {
                            Orgs parentUnit = parents.get(0);
                            //父ID
                            org.setParentId(parentUnit.getId());
                            //ID全路径
                            org.setOrgIdPath(parentUnit.getOrgIdPath() + "/" + unit.getGuidkey());
                            //code全路径
                            org.setOrgCodePath(parentUnit.getOrgCodePath() + "/" + unit.getCodeitemid());
                            //名称全路径
                            org.setOrgNamePath(parentUnit.getOrgNamePath() + "/" + unit.getCodeitemdesc());
                            //排序
                            org.setLevel(parentUnit.getLevel() + 1L);
                            //org.setListOrder(parentUnit.getListOrder()+100L);
                            org.setListOrder(listOrder);
                        }
                        org.setAppCode("JZ");
                        org.setCreateTime(new Date());
                        org.setCreateUserId(CurrentUser.getUserId());

                        if (new Date().before(unit.getStart_date()) || unit.getEnd_date().before(new Date())) {
                            org.setValidStatus(false);
                        } else {
                            org.setValidStatus(true);
                        }
                        org.setVersionNo(newVersion);
                        org.setGenre(Genre);
                        completeUnit.add(org);
                        orgsMapper.insertSelective(org);
                        //BusinessLogger.Info(LoggerGenre.DataSynchronize, "正在同步单位/部门信息", org);
                    } catch (Exception e) {
                        System.out.print("部门同步失败----" + unit.getGuidkey());
                    }
                }
            }
        }
        return true;
    }

    /**
     * 创建人:Coke
     * 备注: 同步岗位
     * 时间: 2019/4/26 13:49
     * 参数:
     */
    public Boolean SyncJob(Object[] objects, Long newVersion, List<Orgs> completeUnit, List<Jobs> completeJob, List<OrgJobs> completeOrgJob) throws Exception {
        if (objects.length > 0) {
            List<JobDto> listUnit = objectMapper.readValue(objects[0].toString(), new TypeReference<List<JobDto>>() {
            });
            BusinessLogger.Info(LoggerGenre.DataSynchronize, "获取到了岗位信息", listUnit);
            if (listUnit != null && listUnit.size() > 0) {
                for (int i = 0; i < listUnit.size(); i++) {
                    Jobs job = new Jobs();
                    JobDto jobData = listUnit.get(i);
                    try {
                        //主键
                        job.setId(jobData.getGuidkey());
                        //部门编码
                        job.setJobCategoryId("38a79fd5dcd34960ac7933ede08cf928");
                        job.setJobCode(jobData.getCodeitemid());
                        //部门名称
                        job.setJobName(jobData.getCodeitemdesc());
                        job.setCreateTime(new Date());
                        job.setCreateUserId(CurrentUser.getUserId());
                        //补充字段
                        job.setStartDate(jobData.getStart_date());
                        job.setEndDate(jobData.getEnd_date());


                        if (new Date().before(jobData.getStart_date()) || jobData.getEnd_date().before(new Date())) {
                            job.setValidStatus(false);
                        } else {
                            job.setValidStatus(true);
                        }
                        job.setVersionNo(newVersion);
                        job.setDeleted(false);
                        completeJob.add(job);
                        jobsMapper.insertSelective(job);
                        //BusinessLogger.Info(LoggerGenre.DataSynchronize, "正在同步岗位信息", job);
                        //同步岗位与部门关系
                        List<Orgs> parents = completeUnit.stream().filter(item -> item.getOrgCode().equals(jobData.getParentid())).collect(Collectors.toList());
                        if (parents != null && parents.size() == 1) {
                            Orgs parentOrg = parents.get(0);
                            OrgJobs orgJobs = new OrgJobs();
                            String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
                            orgJobs.setId(uuid);
                            orgJobs.setOrgId(parentOrg.getId());
                            orgJobs.setJobId(job.getId());
                            orgJobs.setCreateTime(new Date());
                            orgJobs.setCreateUserId(CurrentUser.getUserId());
                            orgJobs.setVersionNo(newVersion);
                            orgJobsMapper.insertSelective(orgJobs);
                            completeOrgJob.add(orgJobs);
                            //BusinessLogger.Info(LoggerGenre.DataSynchronize, "正在同步部门与岗位关系", orgJobs);
                        } else {
                            BusinessLogger.Info(LoggerGenre.DataSynchronize, "同步部门与岗位关系失败,岗位的父ID未找到", job);
                        }
                    } catch (Exception e) {
                        System.out.print("岗位同步失败----" + jobData.getGuidkey());

                    }
                }
            }
        }
        return true;
    }

    /**
     * 创建人:Coke
     * 备注: 同步人员
     * 时间: 2019/4/26 13:49
     * 参数:
     */
    public Boolean SyncUserInfo(Object[] objects, Long newVersion, Long oldVersion, List<Orgs> completeUnit, List<Jobs> completeJob, List<OrgJobs> completeOrgJob) throws Exception {
        if (objects.length > 0) {
            //String str = objects[0].toString().toLowerCase();
            List<UserInfoDto> listUserInfos = objectMapper.readValue(objects[0].toString(), new TypeReference<List<UserInfoDto>>() {
            });
            BusinessLogger.Info(LoggerGenre.DataSynchronize, "获取到人员信息", listUserInfos);
            if (listUserInfos != null && listUserInfos.size() > 0) {
                List<Users> completeUser = new ArrayList<Users>();
                for (int i = 0; i < listUserInfos.size(); i++) {

                    UserInfoDto userInfo = listUserInfos.get(i);
                    try {
                        Users user = new Users();
                        user.setId(userInfo.getA0144());
                        user.setUserCode(userInfo.getA0144());
                        user.setUserName(userInfo.getA0101());
                        user.setPassword("cwe123456");
                        user.setEmail(userInfo.getA0146());
                        //补充字段：
                        user.setUsedName(userInfo.getA0104());
                        user.setEmploymentForm(userInfo.getA01af());
                        user.setUnit(userInfo.getB0110());
                        user.setDepartment(userInfo.getE0122());
                        user.setJob(userInfo.getE01a1());
                        user.setNationality(userInfo.getA0181());
                        user.setConversionDate(userInfo.getA0162());
                        user.setCertificateType(userInfo.getA01bq());
                        user.setCertificateNo(userInfo.getA01bt());
                        user.setActualBirthday(userInfo.getA01bk());
                        user.setAge(userInfo.getA0112());
                        user.setJobType(userInfo.getA0135());
                        user.setJobLevel(userInfo.getA0137());
                        user.setStartWorkDate(userInfo.getA0141());
                        user.setWorkAge(userInfo.getA0151());
                        user.setFullPinyinName(userInfo.getA01at());
                        user.setNation(userInfo.getA0121());
                        user.setNativePlace(userInfo.getA0114());
                        user.setHouseholdRegisterNature(userInfo.getA0174());
                        user.setCurrentAddressReference(userInfo.getA01av());
                        user.setPersonnelStatus(userInfo.getA0182());
                        user.setWorkPlace(userInfo.getA01ak());
                        user.setHighestEducational(userInfo.getA0136());
                        user.setHighestDegree(userInfo.getA01ac());
                        //user.setStartWorkDate(userInfo.getA0141());
                        user.setJoinGroupDate(userInfo.getA0142());
                        user.setGroupAge(userInfo.getA0143());
                        user.setHealth(userInfo.getA0124());
                        user.setMaritalStatus(userInfo.getA0127());
                        user.setJoinUnitDate(userInfo.getA0162());
                        user.setProbationPeriod(userInfo.getA01al());
                        user.setStartProbationDate(userInfo.getA01an());
                        //待定
                        //user.setEndProbationDate(userInfo.getA01am());
                        user.setPoliticsStatus(userInfo.getA01as());
                        user.setCompanyEmail(userInfo.getA01bl());
                        user.setWeixin(userInfo.getA0149());
                        user.setEmergencyContact(userInfo.getA0153());
                        user.setEmergencyContactRelation(userInfo.getA01ar());
                        user.setEmergencyPhone(userInfo.getA0152());
                        user.setIsDepartmentHead(userInfo.getA01bm());
                        user.setIsInDormitoryCondition(userInfo.getA01ag());
                        user.setBankNo(userInfo.getA0190());
                        user.setOpeningBank(userInfo.getA01ao());
                        user.setLinkNumber(userInfo.getA01ap());
                        user.setIsAgentPayFund(userInfo.getA01ai());
                        user.setProvidentFundPersonalNo(userInfo.getA01ah());
                        user.setOriginalCardNo(userInfo.getA01ay());
                        user.setJobNumber1(userInfo.getA01ax());
                        user.setUnitShortName(userInfo.getA01az());
                        user.setHomePhone(userInfo.getA01ba());
                        user.setIsFileTransfer(userInfo.getA01bb());
                        user.setUnitPreCode(userInfo.getA01bd());
                        //user.setCertificateType1(userInfo.getA01bq());

                        //补充字段end

                        if (userInfo.getA0182().equals("在职人员") || userInfo.getA0182().equals("试用期")) {
                            user.setAccountIsDisabled(false);
                        } else {
                            user.setAccountIsDisabled(true);
                        }
                        user.setPhone(userInfo.getA0148());
                        user.setSex(userInfo.getA0107());
                        user.setBirthday(userInfo.getA0111());
                        user.setJobNumber(userInfo.getA0144());
                        user.setCardNo(userInfo.getA0177());
                        user.setDingUserId(userInfo.getA01bz());
                        user.setVersionNo(newVersion);
                        com.appcenter.application.input.user.GetUserInput oldUserInput = new com.appcenter.application.input.user.GetUserInput();
                        oldUserInput.setUserCode(userInfo.getA0144());
                        oldUserInput.setVersionNo(oldVersion);
                        com.appcenter.application.output.user.GetUserOutput curUser = userService.GetUser(oldUserInput);

                        if (curUser != null && curUser.getItem() != null) {
                            user.setOfficePhone(curUser.getItem().getOfficePhone());
                            user.setEmailPassword(curUser.getItem().getEmailPassword());
                            user.setPassword(curUser.getItem().getPassword());
                        }
                        List<Users> users = completeUser.stream().filter(item -> item.getUserCode().equals(userInfo.getA0144())).collect(Collectors.toList());
                        if (users == null || users.size() == 0) {
                            usersMapper.insertSelective(user);
                            completeUser.add(user);
                        }
                        //BusinessLogger.Info(LoggerGenre.DataSynchronize, "正在同步人员信息", user);
                        if (!isBlank(userInfo.getE01a1())) {
                            //关联人员岗位信息
                            JobUsers jobUsers = new JobUsers();
                            String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
                            jobUsers.setId(uuid);
                            List<Jobs> jobs = completeJob.stream().filter(item -> item.getJobCode().equals(userInfo.getE01a1())).collect(Collectors.toList());
                            List<Orgs> orgs = completeUnit.stream().filter(item -> item.getOrgCode().equals(userInfo.getE0122())).collect(Collectors.toList());
                            if (jobs != null && jobs.size() == 1 && orgs != null && orgs.size() == 1) {
                                Jobs job = jobs.get(0);
                                Orgs org = orgs.get(0);
                                List<OrgJobs> orgjob = completeOrgJob.stream().filter(item -> item.getOrgId().equals(org.getId()) && item.getJobId().equals(job.getId())).collect(Collectors.toList());
                                if (orgjob != null && orgjob.size() > 0) {
                                    jobUsers.setOrgJobId(orgjob.get(0).getId());
                                    jobUsers.setUserId(user.getId());
                                    jobUsers.setCreateTime(new Date());
                                    jobUsers.setCreateUserId(CurrentUser.getUserId());
                                    jobUsers.setMain(true);
                                    jobUsers.setVersionNo(newVersion);
                                    jobUsersMapper.insertSelective(jobUsers);
                                    //BusinessLogger.Info(LoggerGenre.DataSynchronize, "正在同步人员岗位关系信息", jobUsers);
                                } else {
                                    BusinessLogger.Info(LoggerGenre.DataSynchronize, "同步人员岗位关系失败,组织岗位关系未找到.OrgId=" + org.getId() + ",JobId=" + job.getId() + "UserID=" + user.getId());
                                }
                            } else {
                                BusinessLogger.Info(LoggerGenre.DataSynchronize, "同步人员岗位关系失败,组织岗位关系未找到", userInfo);
                            }
                        }
                    } catch (Exception e) {
                        System.out.print("人员同步失败----" + userInfo.getA0101());
                    }
                }
            }
        }


        return true;
    }

    /**
     * 创建人:Coke
     * 备注: 同步人员兼岗信息
     * 时间: 2019/4/26 13:49
     * 参数:
     */
    public Boolean SyncUserpluralism(Object[] objects, Long newVersion, List<OrgJobs> completeOrgJob, List<Jobs> completeJob, List<Orgs> completeUnit) throws Exception {
        if (objects.length > 0) {
            String str = objects[0].toString().toLowerCase();
            List<JobUserDto> listJobUsers = objectMapper.readValue(str, new TypeReference<List<JobUserDto>>() {
            });
            BusinessLogger.Info(LoggerGenre.DataSynchronize, "获取到兼职信息", listJobUsers);

            if (listJobUsers != null && listJobUsers.size() > 0) {
                for (int i = 0; i < listJobUsers.size(); i++) {
                    JobUserDto jobUser = listJobUsers.get(i);

                    try {
                        List<Jobs> curJobs = completeJob.stream().filter(item -> item.getJobCode().equals(jobUser.getA0904())).collect(Collectors.toList());


                        List<Orgs> curOrgs = completeUnit.stream().filter(item -> item.getOrgCode().equals(jobUser.getA0902())).collect(Collectors.toList());

                        if (curJobs != null && curOrgs != null && curJobs.size() == 1 && curOrgs.size() == 1) {
                            Jobs curJob = curJobs.get(0);
                            Orgs curOrg = curOrgs.get(0);
                            List<OrgJobs> orgjob = completeOrgJob.stream().filter(item -> item.getOrgId().equals(curOrg.getId()) && item.getJobId().equals(curJob.getId())).collect(Collectors.toList());
                            JobUsers jobUsers = new JobUsers();
                            String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
                            jobUsers.setId(uuid);
                            if (orgjob != null && orgjob.size() > 0) {
                                jobUsers.setOrgJobId(orgjob.get(0).getId());
                                jobUsers.setUserId(jobUser.getA0144());
                                jobUsers.setCreateTime(new Date());
                                jobUsers.setCreateUserId(CurrentUser.getUserId());
                                jobUsers.setMain(false);
                                jobUsers.setVersionNo(newVersion);
                                jobUsersMapper.insertSelective(jobUsers);
                                //BusinessLogger.Info(LoggerGenre.DataSynchronize, "正在同步兼岗信息", jobUsers);
                            } else {
                                BusinessLogger.Info(LoggerGenre.DataSynchronize, "同步人员兼岗信息失败,组织岗位关系未找到.OrgId=" + jobUser.getA0902() + ",JobId=" + jobUser.getA0904() + "UserId=" + jobUser.getA0144());
                            }
                        }
                    } catch (Exception e) {
                        System.out.print("兼岗同步失败----" + jobUser.getA0144());
                    }
                }
            }


        }
        return true;

    }

    /**
     * 创建人:Coke
     * 备注: 历史数据清除
     * 时间: 2019/4/26 13:49
     * 参数:
     */
    public Boolean ClearData() throws Exception {
        try {

            //getData();

            Long version = objectFinal.getDataEffectiveVersion();
            //清除用户历史数据
            Example userExample = new Example(Users.class);
            Example.Criteria userCriteria = userExample.createCriteria();
            userCriteria.andNotEqualTo("versionNo", version);
            //userCriteria.andNotEqualTo("versionNo", 2);
            usersMapper.deleteByExample(userExample);

            //清除组织历史数据
            Example orgExample = new Example(Orgs.class);
            Example.Criteria orgCriteria = orgExample.createCriteria();
            orgCriteria.andNotEqualTo("versionNo", version);
            //orgCriteria.andNotEqualTo("versionNo", 2);
            orgsMapper.deleteByExample(orgExample);

            //清除组织人员关系数据
            Example orguserExample = new Example(Orgs.class);
            Example.Criteria orguserCriteria = orguserExample.createCriteria();
            orguserCriteria.andNotEqualTo("versionNo", version);
            //orguserCriteria.andNotEqualTo("versionNo", 2);
            orgUsersMapper.deleteByExample(orguserExample);


            //清除岗位历史数据数据
            Example jobExample = new Example(Orgs.class);
            Example.Criteria jobCriteria = jobExample.createCriteria();
            jobCriteria.andNotEqualTo("versionNo", version);
            //jobCriteria.andNotEqualTo("versionNo", 2);
            jobsMapper.deleteByExample(jobExample);

            //清除组织岗位历史数据
            Example orgjobExample = new Example(Orgs.class);
            Example.Criteria orgjobCriteria = orgjobExample.createCriteria();
            orgjobCriteria.andNotEqualTo("versionNo", version);
            //orgjobCriteria.andNotEqualTo("versionNo", 2);
            orgJobsMapper.deleteByExample(orgjobExample);


            //清除岗位人员历史数据
            Example jobuserExample = new Example(Orgs.class);
            Example.Criteria jobuserCriteria = jobuserExample.createCriteria();
            jobuserCriteria.andNotEqualTo("versionNo", version);
            //jobuserCriteria.andNotEqualTo("versionNo", 2);
            jobUsersMapper.deleteByExample(jobuserExample);


        } catch (Exception e) {
            throw new ErrorJsonResult("1000031", "失败");
        }
        return true;
    }


    /**
     * 创建人:Coke
     * 备注: 测试
     * 时间: 2019/4/26 13:52
     * 参数:
     */
    public void getData() throws Exception {
        JaxWsDynamicClientFactory dcfJobUser = JaxWsDynamicClientFactory.newInstance();
        Client clientJobUser = dcfJobUser.createClient(remoteProperties.getHrUserService());
        Object[] objectJobUsers = clientJobUser.invoke("getJRuserpost");
        String str = objectJobUsers[0].toString().toLowerCase();
        List<JobUserDto> listJobUsers = objectMapper.readValue(str, new TypeReference<List<JobUserDto>>() {
        });
    }

}
